luffy.common.Statistics = jindo.$Class({
	TEMPLATE : {
		STAT : "stat_form"		
	},
	$init : function(){
		this.oTpl = {};
		this.oTpl.stat = luffy.common.TemplateRepos.get(this.TEMPLATE.STAT);
		
		this.wel = {};
		this.wel.stat = jindo.$Element(jindo.$("<div class='statistics'>"));
		document.body.appendChild(this.wel.stat.$value());
		this.wel.stat.hide();
		
		this._isInit = false;
		
		this.DataManager = new luffy.common.StatisticsDataManager();
		this.DataManager.attach({
			"recieveStat" : jindo.$Fn(this.CustomEventHandler._onRecieveStat, this).bind(),
			"failRequest" : jindo.$Fn(this.CustomEventHandler._onFailRecieveLottoList, this).bind()
		});
	},
	
	_renderStat : function(oData,elParent){
		var sHtml = this.oTpl.stat.process(oData);
		jindo.$Element(elParent).html(sHtml);
		this._isInit = true;
		this.show();
	},
	
	initStatByVisit : function(){
		this.DataManager.requestIncreaseVisit();						
	},
	
	increaseUse : function(){
		this.DataManager.requestIncreaseUse();						
	},
	
	show : function(){
		if(this._isInit == false){
			this.DataManager.requestAllCount();						
		}else{
			this._setStatPosition();
			this.wel.stat.show();
		}
		
	},
	
	_setStatPosition : function(){
	},
	
	CustomEventHandler : {
		/**
		 * 리스트를 받아 왔을때 렌더링 한다.
		 */
		_onRecieveStat : function(oEvent){
			this._renderStat(oEvent.oData, this.wel.stat.$value());
		},
		
		/**
		 * 리스트를 받아 오는데 실패 했다면 실패를 렌더링 한다.
		 */
		_onFailRecieveLottoList : function(oEvent){
			alert(oEvent.error.message);
		}
		
	}
});